package kr.co.doriclassic.chapter22;

import java.io.Serializable;

/**1번째 작업
 * @author M201_06
 *
 */
public class Student implements Serializable, Comparable<Student>{
	/**이전정보인지 최신 정보인지 비교
	 * 20141013
	 */
	private int stdNum;
	private String stdName;
	private int kor;
	private int eng;
	private int math;
	
	public Student(int stdNum, String stdName) {
		this.stdNum = stdNum;
		this.stdName = stdName;
	}

	public Student(int stdNum, String stdName, int kor, int eng, int math) {
		this.stdNum = stdNum;
		this.stdName = stdName;
		this.kor = kor;
		this.eng = eng;
		this.math = math;
	}

	public int getStdNum() {
		return stdNum;
	}

	public void setStdNum(int stdNum) {
		this.stdNum = stdNum;
	}

	public String getStdName() {
		return stdName;
	}

	public void setStdName(String stdName) {
		this.stdName = stdName;
	}

	public int getKor() {
		return kor;
	}

	public void setKor(int kor) {
		this.kor = kor;
	}

	public int getEng() {
		return eng;
	}

	public void setEng(int eng) {
		this.eng = eng;
	}

	public int getMath() {
		return math;
	}

	public void setMath(int math) {
		this.math = math;
	}
	
	public int totalScore(){
		return kor+eng+math;
	}
	
	public double avgScore(){
		return totalScore()/3.0;
	}

	@Override
	public String toString() {
		return String
				.format("%3s\t%5s\t%3s\t%3s\t%3s\t%3s\t%6.3f]",
						stdNum, stdName, kor, eng, math, totalScore(),
						avgScore());
	}

	@Override//search를 위한 equals
	public boolean equals(Object obj) {
		if(obj instanceof Student){
			//비교할 객체 생성
			Student temp = (Student) obj;	
			return stdNum==temp.stdNum&&stdName.equals(temp.stdName);
		}
		else {
			return false;
		}		
	}

	@Override//기본정렬
	public int compareTo(Student o) {
		// 학번을 기본으로정렬, 인터페이스 구현은 기본을 의미함, 익명클래스는 개별 적용
		return stdNum-o.stdNum;
	}		
}
